package net.stogi.unicore.beyond.ui.client.taskeditor.taskoutline;

import java.util.HashMap;
import java.util.Map;

import net.stogi.common.gwt.dispatch.client.core.ActionManager;
import net.stogi.common.gwt.frame.client.core.EventBus;
import net.stogi.common.gwt.frame.client.module.Module;
import net.stogi.common.gwt.frame.client.mvp.AbstractPresenter;

import com.google.gwt.user.client.ui.Widget;

public class TaskOutlineModule implements Module {

	public static final String TASK_OUTLINE_PRESENTER = "task-outline-presenter";

	public static final String TASK_OUTLINE_WIDGET = "task-outline-widget";
	
	public static final String PROPERTY_EDITOR_PRESENTER = "property-editor-presenter";

	public static final String PROPERTY_EDITOR_WIDGET = "property-editor-widget";

	private ActionManager actionManager;

	private EventBus eventBus;

	private Map<String, AbstractPresenter> presenterMap = new HashMap<String, AbstractPresenter>();

	private Map<String, Widget> widgetMap = new HashMap<String, Widget>();

	public TaskOutlineModule(ActionManager actionManager, EventBus eventBus) {
		this.actionManager = actionManager;
		this.eventBus = eventBus;
		initModule();
	}

	@Override
	public Widget getWidget(String name) {
		return widgetMap.get(name);
	}

	protected void initModule() {
		TaskOutlineWidget taskOutlineWidget = new TaskOutlineWidget();
		TaskOutlinePresenter taskOutlinePresenter = new TaskOutlinePresenter(taskOutlineWidget, actionManager, eventBus);
		PropertyEditorWidget propertyEditorWidget = new PropertyEditorWidget();
		PropertyEditorPresenter propertyEditorPresenter = new PropertyEditorPresenter(propertyEditorWidget, actionManager, eventBus);
		// Register widgets and presenters.
		widgetMap.put(TASK_OUTLINE_WIDGET, taskOutlineWidget);
		presenterMap.put(TASK_OUTLINE_PRESENTER, taskOutlinePresenter);
		widgetMap.put(PROPERTY_EDITOR_WIDGET, propertyEditorWidget);
		presenterMap.put(PROPERTY_EDITOR_PRESENTER, propertyEditorPresenter);
	}
}
